/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TrongChien
 */
public class ChagesLanguage {

    public static String languageCode = "";
    public static String countryCode = "";
    public static String urlLanguage = "";

    public static void readFileLanguage() {
        BufferedReader bf = null;
        try {
            bf = new BufferedReader(new InputStreamReader(new FileInputStream("src/Common/language.dat")));
            String line = null;
            try {
                while ((line = bf.readLine()) != null) {
                    String[] a = line.split(";");
                    for (int i = 0; i < a.length; i++) {
                        languageCode = a[0];
                        countryCode = a[1];
                    }
                }
                if (languageCode == "vi") {
                    urlLanguage = "language/language_vi_VN";
                } else {
                    urlLanguage = "language/language";
                }
                //System.out.println("languageCode"+languageCode);
                //System.out.println("countryCode"+countryCode);
            } catch (IOException ex) {
                Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void writeFileLanguageUS() {
        FileOutputStream fop = null;
        File file;
        String content = "en;US";
        file = new File("src/Common/language.dat");
        try {
            fop = new FileOutputStream(file);
            if (!file.exists()) {
                file.createNewFile();
            }
            byte[] contentInBytes = content.getBytes();
            fop.write(contentInBytes);
            fop.flush();
            fop.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (fop != null) {
                try {
                    fop.close();
                } catch (IOException ex) {
                    Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    public static void writeFileLanguageVN() {
        FileOutputStream fop = null;
        File file;
        String content = "vi;VN";
        file = new File("src/Common/language.dat");
        try {
            fop = new FileOutputStream(file);
            if (!file.exists()) {
                file.createNewFile();
            }
            byte[] contentInBytes = content.getBytes();
            fop.write(contentInBytes);
            fop.flush();
            fop.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (fop != null) {
                try {
                    fop.close();
                } catch (IOException ex) {
                    Logger.getLogger(ChagesLanguage.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}
